export default {
  data() {
    return {
      Timer: 0,
    }
  },
  mounted() {
    this.getLastBlock()
    this.Timer = setInterval(() => {
      this.getLastBlock();
    }, 10000);
  },
  methods: {
    // 获取最新区块
    getLastBlock() {
      this.Rpc.getLastHeader().then((data) => {
        if (data.error === null) {
          if (data.result.height !== this.$store.state.maxHeight) {
            this.$store.commit('updateMaxHeight', data.result.height)
            this.$store.commit('updateMaxBlockHash', data.result.hash)
            return
          }
        }
      })
    },
  },
  beforeDestroy() {
    //清除定时器
    clearTimeout(this.Timer);
  }
}